Restrict VLM padding workaround to transformers 5.3.0#5503
Merged
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
qgallouedec
approved these changes
Apr 10, 2026
| # Workaround for a bug in transformers 5.3.0 where some processors (e.g. Qwen2.5-VL) crash on | ||
| # batched unpadded input (transformers#44514). | ||
| # Fixed in transformers 5.4.0 (transformers#44563). | ||
| needs_padding_workaround = Version("5.3.0") <= Version(transformers.__version__) < Version("5.4.0") |
Member
There was a problem hiding this comment.
So we were wrong, it was introduced in 5.3 not 5.2?
Member
Author
There was a problem hiding this comment.
Yes, I tested locally.
The original comment also incorrectly attributed the bug to transformers 5.2.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Restrict VLM padding workaround to transformers 5.3.0.
This PR updates the prompt tokenization logic in several trainer classes to handle a specific bug in the
transformerslibrary more robustly. The main change is to apply a padding workaround only for affectedtransformersversions (5.3.x), and to simplify the logic for handling padded and unpadded input IDs. This avoids unnecessary padding for unaffected versions and ensures compatibility with future releases.Additionally, this PR fixes:
processor.__call__have to be inprocessor_kwargsdict, not in**kwargs#5502padding=True, but only with transformers >= 5.4.0Fix #5502.
Motivation
The bug (
Qwen2_5_VLProcessor.apply_chat_templatecrashing on batched unpadded input) was introduced in transformers 5.3.0:Qwen2_5_VLProcessor.apply_chat_templatecrashes on batched input whenpadding=Falsetransformers#44514The bug was fixed in 5.4.0
mm_token_typebe non-padded lists transformers#44563In
trl, it was fixed withpadding=Trueworkaround in_tokenize_prompts(GRPO, RLOO, DPPO trainers) that was applied unconditionally to all transformers versions_generate_single_turn#5239Solution
Version("5.3.0") <= Version(transformers.__version__) < Version("5.4.0")padding=Trueonly when the workaround is active; omit the argument entirely otherwise (see Warning log: Kwargs passed toprocessor.__call__have to be inprocessor_kwargsdict, not in**kwargs#5502)tokenized["input_ids"]directlyChanges
Bug workaround and version handling:
transformerslibrary version (>=5.3.0 and <5.4.0) to determine if the padding workaround should be applied, instead of always applying padding. (GRPO, RLOO, and experimental DPPO)transformers5.3.0 and fixed in 5.4.0, with references to the relevant GitHub issues and PRs.Prompt ID extraction logic:
input_idsusing theattention_maskwhen the workaround is needed; otherwise, uses the tokenizedinput_idsdirectly, simplifying the code path for unaffected versions.Note
Medium Risk
Touches prompt tokenization in multiple trainers; version-gated padding/unpadding could change input IDs for some
transformersversions and affect multimodal generation edge cases.Overview
Restricts the VLM
apply_chat_templatepadding workaround totransformersversions>=5.3.0and<5.4.0, instead of always forcingpadding=True.When the workaround is inactive, the trainers now skip the unpadding step and use
tokenized["input_ids"]directly; comments were updated to reference the correct upstream bug/fix (transformers#44514/#44563).Reviewed by Cursor Bugbot for commit cf3dbe2. Bugbot is set up for automated code reviews on this repo. Configure here.